﻿function RemoveRecordController(recordId) {
    this.RecordId = recordId;
};
RemoveRecordController.prototype.RemoveWithConfirm = function () {
    var controller = this;
    $('<div id="dialog-confirm" title="Usuń wpis?"><p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>Wpis zostanie bezpowrotnie usunięty. <br /><br />Jesteś pewien?</p></div>')
        .dialog({
            resizable: false,
            height: 170,
            modal: true,
            buttons: {
                "Anuluj": function () {
                    $(this).dialog("close");
                },
                "Usuń": function () {
                    controller.Remove();
                    $(this).dialog("close");
                }
            }
        });
};

RemoveRecordController.prototype.Remove = function () {
    var $form = $('form');
    $('<input type="hidden" name="action" value="RemoveRecord" />').appendTo($form);
    $('<input type="hidden" name="recordId" value="' + this.RecordId + '" />').appendTo($form);
    $form.submit();
};

$(function () {
    $('a[href^=remove-record]').click(function (e) {
        e.preventDefault();
        var href = $(this).attr('href');
        if (href) {
            var hrefParts = href.split(':');
            if (hrefParts.length == 2) {
                var recordId = parseInt(hrefParts[1]);
                if (recordId) {
                    var rrc = new RemoveRecordController(recordId);
                    rrc.RemoveWithConfirm();
                }
            }
        }
    });
});
